package com.zhang.crawler.crawler.utils;

import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @author zhanghaidong
 * @version v1.0
 * @description
 * @date 2019/5/29
 */
public class  Tools {
    /**
     * 研发中心领域
     */
    public static final Map<String,String> RESEARCH_CENTRE = new HashMap<String, String>(){{
//        put("-1","全部");
//        put("0","不限");
        put("1","资源环境");
        put("2","现代农业");
        put("3","装备制造");
        put("4","信息技术");
        put("5","生物医药");
        put("6","纺织服装");
        put("7","食品营养");
        put("8","交通运输");
        put("9","节能建筑");
        put("10","IT互联网");
        put("11","科技服务");
        put("12","化学化工");
        put("13","海洋科技");
        put("14","新能源");
        put("15","新材料");
        put("16","其他");
    }};
    /**
     * 专家职称
     */
    public static final Map<String,String> EXPERTS_TITLE = new HashMap<String, String>(){{
        put("1","研究员");
        put("2","工程师");
        put("3","高级工程师");
        put("4","讲师");
        put("5","副教授");
        put("6","教授");
        put("7","博士");
        put("8","院士");
    }};
    /**
     * 专家类型
     */
    public static final Map<String, String> EXPERTS_TYPE = new HashMap<String, String>(){{
        //put("0","不限");
        put("1","高校专家");
        put("2","企业专家");
        put("3","院所专家");
    }};
    /**
     * 地区---目前该Map只在帅选条件里使用
     */
    public static final Map<String, String> COMPANY_LOCATION=new HashMap<String, String>(){{
        put("110000","北京市");
        put("120000","天津市");
        put("130000","河北省");
        put("140000","山西省");
        put("150000","内蒙古自治区");
        put("210000","辽宁省");
        put("220000","吉林省");
        put("230000","黑龙江省");
        put("310000","上海市");
        put("320000","江苏省");
        put("330000","浙江省");
        put("340000","安徽省");
        put("350000","福建省");
        put("360000","江西省");
        put("370000","山东省");
        put("410000","河南省");
        put("420000","湖北省");
        put("430000","湖南省");
        put("440000","广东省");
        put("450000","广西壮族自治区");
        put("460000","海南省");
        put("500000","重庆市");
        put("510000","四川省");
        put("520000","贵州省");
        put("530000","云南省");
        put("540000","西藏自治区");
        put("610000","陕西省");
        put("620000","甘肃省");
        put("630000","青海省");
        put("640000","宁夏回族自治区");
        put("650000","新疆维吾尔自治区");
        put("710000","台湾省");
        put("810000","香港特别行政区");
        put("820000","澳门特别行政区");
//        put("130100","石家庄");
//        put("140100","太原");
//        put("150100","呼和浩特");
//        put("310100","上海");
//        put("440300","深圳");
    }};

    /**
     * 行业类型
     */
    public static final Map<String, String> INDUSTRY_TYPE = new HashMap<String, String>(){{
        //put("-1","不限");
        put("0","农、林、牧、渔业");
        put("1","采矿业");
        put("2","制造业");
        put("3","建筑业");
        put("4","批发和零售业");
        put("5","电力、热力、燃气及水生产和供应业");
        put("6","信息传输、软件和信息技术服务业");
        put("7","金融业");
        put("8","房地产业");
        put("9","租赁和商务服务业");
        put("10","科学研究和技术服务业");
        put("11","教育");
        put("12","其他行业");
//        put("13","社交网络");
//        put("14","人力资源服务");
//        put("15","企业服务");
//        put("16","信息安全");
//        put("17","智能硬件");
//        put("18","移动互联网");
//        put("19","互联网");
//        put("20","计算机软件");
//        put("21","通信/网络设备");
//        put("22","广告/公关/会展");
//        put("23","互联网金融");
//        put("24","物流/仓储");
//        put("25","贸易/进出口");
//        put("26","咨询");
//        put("27","工程施工");
//        put("28","汽车生产");
//        put("29","其他行业");
    }};
    /**
     * 公司规模
     */
    public static final Map<String, String> COMPANY_SIZE = new HashMap<String, String>(){{
        //put("-1","全部");
        put("0","20人以下");
        put("1","20-99人");
        put("2","100-499人");
        put("3","500-999人");
        put("4","1000-9999人");
        put("5","10000以上");
    }};
    /**
     * 融资阶段
     */
    public static final Map<String, String> FINANCING_STAGE = new HashMap<String, String>(){{
        //put("-1","不限");
        put("0","未融资");
        put("1","天使轮");
        put("2","A轮");
        put("3","B轮");
        put("4","C轮");
        put("5","D轮及以上");
        put("6","上市公司");
    }};
    /**
     * 薪资要求
     */
    public static final Map<String, String> SALARY_RENDER=new HashMap<String, String>(){
        {
            //put("-1","全部");
            put("0","3K以下");
            put("1","3-5K");
            put("2","5-10k");
            put("3","10-15k");
            put("4","15-20k");
            put("5","20-30k");
            put("6","30-50k");
            put("7","50k以上");
        }
    };
    /**
     * 学历要求
     */
    public static final Map<String, String> EDUCATION_RENDER=new HashMap<String, String>(){{
//        put("-1","全部");
//        put("0","不限");
        put("1","大专");
        put("2","本科");
        put("3","硕士");
        put("4","博士");
    }};

    /**
     工作经验
     */
    public static final Map<String, String> WORK_EXPERIENCE=new HashMap<String, String>(){{
//        put("-1","全部");
//        put("0","不限");
        put("1","应届");
        put("2","3年及以下");
        put("3","3-5年");
        put("4","5-10年");
        put("5","10年以上");
    }};

    /**
     * 工作城市
     */

    public static final Map<String, String> WORK_CITY=new HashMap<String, String>(){{
        put("110100","北京市");
        put("120100","天津市");
        put("130100","石家庄市");
        put("140100","太原市");
        put("150100","呼和浩特市");
        put("310100","上海市");
        put("440300","深圳市");
    }};

    /**
     * 职位类型
     */
    public static final Map<String, String> POSITION_TYPE=new HashMap<String, String>(){{
        //put("-1","全部");
        put("0","技术");
        put("1","产品");
        put("2","设计");
        put("3","运营");
        put("4","市场");
        put("5","销售");
        put("6","职能");
        put("7","其他");
    }};
    /**
     * 工作性质
     */
    public static final Map<String, String> NATURE_WORK=new HashMap<String, String>(){{
        put("1","全职");
        put("2","兼职");
    }};

    /**
     * 专利类型
     */
    public static final Map<String, String> PATENT_TYPE = new HashMap<String, String>(){{
        put("1", "发明专利");
        put("2", "实用新型专利");
        put("3", "外观设计专利");
    }};

    /**
     * 专利领域
     *
     */
    public static final Map<String, String> PATENT_FIELD = new HashMap<String, String>(){{
        put("1", "资源环境");
        put("2", "现代农业");
        put("3", "装备制造");
        put("4", "信息技术");
        put("5", "生物医药");
        put("6", "纺织服装");
        put("7", "食品营养");
        put("8", "交通运输");
        put("9", "节能建筑");
        put("10", "IT互联网");
        put("11", "科技服务");
        put("12", "化学化工");
        put("13", "海洋科技");
        put("14", "新能源");
        put("15", "新材料");
        put("16", "其他");
    }};

    /**
     * 专利所属机构
     */
    public static final Map<String, String> PATENT_AFFILIATION = new HashMap<String, String>(){{
        put("1", "大专院校");
        put("2", "科研院所");
        put("3", "事业单位");
        put("4", "企业");
        put("5", "个人");
    }};
    /**
     * 项目类型
     */
    public static final Map<String, String> PROJECT_TYPE = new HashMap<String, String>(){{
        put("1","高校项目");
        put("2","企业项目");
        put("3","院所项目");
    }};
    /**
     * 项目阶段
     */
    public static final Map<String, String> PROJECT_PHASE = new HashMap<String, String>(){{
        put("1","研发阶段");
        put("2","实验室阶段");
        put("3","概念阶段");
        put("4","小批量生产阶段");
        put("5","规模化生产阶段");
        put("6","市场推广阶段");
    }};

    /**
     * 活动状态
     */
    public static final Map<String, String> ACTIVITY_STATUS = new HashMap<String, String>(){{
        put("-1","全部");
        put("0","进行中");
        put("1","已结束");
        put("2","未发布");
        put("3","即将开始");
    }};
    /**
     *  园区 A、B座
     */
    public static final Map<String, String> GARDEN_BUILD = new HashMap<String, String>(){{
        put("0","A座");
        put("1","B座");
    }};
    /**
     *  开发平台
     * '所属级别,1.国家，2.省/直辖市，3.地/市级，4.县/区，5.镇/乡'
     */
    public static final Map<String, String> OPEN_API_TECHNOLOGY_LEVEL = new HashMap<String, String>(){{
        put("1","国家");
        put("2","省/直辖市");
        put("3","地/市级");
        put("4","县/区");
        put("5","镇/乡");
    }};
    /**
     * 开发平台---行业领域
     */
    public static final Map<String, String> OPEN_API_TECHNOLOGY_INDUSTRY = new HashMap<String, String>(){{
        put("6", "新能源与节能");
        put("9", "生态农业与开发");
        put("7", "自然资源与环境");
        put("8", "先进制造与自动化");
        put("10", "食品加工生产");
        put("5", "高技术服务与检验检测");
        put("", "不限");
        put("不限", "不限");
        put(null, "不限");
        put("3", "航空航天");
        put("4", "新材料");
        put("1", "电子信息技术");
        put("2", "生物与新医药");
        put("11", "商贸流通与进出口贸易");
    }};

    /**
     * 新闻分类
     */
    public static final Map<String,String> NEWS_CATEGORY = new HashMap<String, String>(){{
        put("0","其他");
        put("1","产业信息");
        put("2","行业信息");
        put("3","专业数据");
        put("4","专家解读");
        put("5","信息交互");
    }};
    /**
     *
     * @param types
     * @return
     */
    public static Map<String, List<JSONObject>> getByTypes(String[] types) {
        Map<String, List<JSONObject>> rs = new HashMap<>();
        for (String str: types){
            switch (str)
            {
                case "SALARY_RENDER":
                    rs.put("SALARY_RENDER", parseMapToObj(SALARY_RENDER));
                    continue;
                case "EDUCATION_RENDER":
                    rs.put("EDUCATION_RENDER", parseMapToObj(EDUCATION_RENDER));
                    continue;
                case "WORK_EXPERIENCE":
                    rs.put("WORK_EXPERIENCE", parseMapToObj(WORK_EXPERIENCE));
                    continue;
                case "WORK_CITY":
                    rs.put("WORK_CITY", parseMapToObj(WORK_CITY));
                    continue;
                case "POSITION_TYPE":
                    rs.put("POSITION_TYPE", parseMapToObj(POSITION_TYPE));
                    continue;
                case "NATURE_WORK":
                    rs.put("NATURE_WORK", parseMapToObj(NATURE_WORK));
                    continue;
                case "FINANCING_STAGE":
                    rs.put("FINANCING_STAGE", parseMapToObj(FINANCING_STAGE));
                    continue;
                case "COMPANY_SIZE":
                    rs.put("COMPANY_SIZE", parseMapToObj(COMPANY_SIZE));
                    continue;
                case "INDUSTRY_TYPE":
                    rs.put("INDUSTRY_TYPE", parseMapToObj(INDUSTRY_TYPE));
                    continue;
                case "COMPANY_LOCATION":
                    rs.put("COMPANY_LOCATION", parseMapToObj(COMPANY_LOCATION));
                    continue;
                case "RESEARCH_CENTRE":
                    rs.put("RESEARCH_CENTRE", parseMapToObj(RESEARCH_CENTRE));
                    continue;
                case "EXPERTS_TITLE":
                    rs.put("EXPERTS_TITLE", parseMapToObj(EXPERTS_TITLE));
                    continue;
                case "EXPERTS_TYPE":
                    rs.put("EXPERTS_TYPE", parseMapToObj(EXPERTS_TYPE));
                    continue;
                case "PATENT_TYPE":
                    rs.put("PATENT_TYPE", parseMapToObj(PATENT_TYPE));
                    continue;
                case "PATENT_FIELD":
                    rs.put("PATENT_FIELD", parseMapToObj(PATENT_FIELD));
                    continue;
                case "PATENT_AFFILIATION":
                    rs.put("PATENT_AFFILIATION", parseMapToObj(PATENT_AFFILIATION));
                    continue;
                case "PROJECT_TYPE":
                    rs.put("PROJECT_TYPE", parseMapToObj(PROJECT_TYPE));
                    continue;
                case "PROJECT_PHASE":
                    rs.put("PROJECT_PHASE", parseMapToObj(PROJECT_PHASE));
                    continue;
                case "GARDEN_BUILD":
                    rs.put("GARDEN_BUILD", parseMapToObj(GARDEN_BUILD));
                    continue;
                case "NEWS_CATEGORY":
                    rs.put("NEWS_CATEGORY", parseMapToObj(NEWS_CATEGORY));
                    continue;
                default:
                    continue;
            }
        }
        return rs;
    }

    /**
     * 筛选条件地区筛选
     * @param type
     * @return
     */
    public static List<JSONObject> getByArea(String type) {
        Map<String, String> rs = new HashMap<>();
        String[] types=type.split("-");
        for (String str: types){
            String swStr=str.substring(0,6);
            rs.put(swStr,COMPANY_LOCATION.get(swStr));
        }
        return parseMapToObj(rs);
    }

    private static List<JSONObject> parseMapToObj (Map<String, String> map) {
        List<JSONObject> list = new ArrayList<>();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            JSONObject rs = new JSONObject();
            rs.put("label", entry.getValue());
            rs.put("value", entry.getKey());
            list.add(rs);
        }
        return list;
    }

    private static Map<String, Object> cache = new HashMap<>();

    static {
        PATENT_TYPE.forEach((k, v) -> cache.put("PATENT_TYPE:" + k, v));
        PATENT_FIELD.forEach((k, v) -> cache.put("PATENT_FIELD:" + k, v));
        PATENT_AFFILIATION.forEach((k, v) -> cache.put("PATENT_AFFILIATION:" + k, v));
    }

    public static String value2Label (String value) {
        Object obj = cache.get(value);
        if (obj != null) {
            return (String) obj;
        }
        return value;
    }

    /**
     * 地区参数-孙亮
     */
    public static void region(){

    }

    public static String value2code(String value, Map<String, String> map){

        AtomicReference<String> result = new AtomicReference<>();
        map.forEach((k, v) -> {
            if (value.contains(v) || v.contains(value)) {
                result.set(k);
                return;
            }
        });
        return result.get();
    }
}

